//
//  LGSketchCell.m
//  ALS3.0
//
//  Created by guomianxiang on 2017/4/7.
//  Copyright © 2017年 guomianxiang. All rights reserved.
//

#import "LGSketchCell.h"
#import "LGDCCellContent.h"
#import "ALSHeader.h"
@implementation LGSketchCell


- (void)setContent:(LGDCCellContent *)content {
    [super setContent:content];

    [self.pictureView setImage:content.image];
    self.sketchCellState = content.sketchCellState;
    if (content.door) {
        self.titleLab.text = @"门名称";
        if (content.door.attributedName) {
            self.contentLab.attributedText = content.door.attributedName;
        }else {
            self.contentLab.text = content.door.doorName;
        }
        
//        if (content.door.favorite == 1) {
//            self.backgroundImageView.hidden = NO;
//        }else {
//            self.backgroundImageView.hidden = YES;
//        }
        
        self.detailLab1.text = [NSString stringWithFormat:@"IP:%@",content.door.ip];
        self.detailLab2.hidden = YES;
        self.addDCView.hidden = YES;
        
        
    }else if (content.controller) {
        
        self.titleLab.text = @"控制器";
        self.cameraView.hidden = YES;
        
        if (content.controller.search) {
            self.contentLab.text = content.controller.sn;
            self.detailLab2.hidden = NO;
            self.detailLab1.text = [NSString stringWithFormat:@"MAC:%@",content.controller.mac];
            self.detailLab2.text = [NSString stringWithFormat:@"IP:%@",content.controller.ip];
            self.addDCView.hidden = NO;
            self.addedImageView.hidden = !content.controller.exist;
            self.addImageView.hidden = !self.addedImageView.hidden;
        }else {
            self.contentLab.text = content.controller.name;
            self.detailLab1.text = [NSString stringWithFormat:@"IP:%@",content.controller.ip];
            self.detailLab2.hidden = YES;
            self.addDCView.hidden = YES;
        }
    }

    self.separatorView.hidden = NO;
    [self updateConstraints];
}

- (void)updateConstraints {
    
    if (self.pictureView.image) {
        self.ContentViewLeadingConstraint.constant = 57;
    }else {
        self.ContentViewLeadingConstraint.constant = 12;
    }
    
//    if (_sketchCellState == LGSketchCellSearchState) {
//        self.separatorLeadingConstraint.constant = 0;
//    }else {
//        self.separatorLeadingConstraint.constant = 0;
//    }
    
    [super updateConstraints];
}

- (void)setSketchCellState:(LGSketchCellState)sketchCellState {
    _sketchCellState = sketchCellState;
    switch (sketchCellState) {
        case LGSketchCellSearchState:
        {
            self.backgroundImageView.hidden = NO;
//            self.backgroundColor = [UIColor whiteColor];
//            
//            self.titleLab.textColor = [UIColor blackColor];
//            self.contentLab.textColor = [UIColor blackColor];
//            self.colonLab.textColor = [UIColor blackColor];
//            
//            self.detailLab1.textColor = kGrayColor(175);
//            self.detailLab2.textColor = kGrayColor(175);
//            self.separatorView.backgroundColor = kGrayColor(238);
        }
            break;
        case LGSketchCellDefaultState:
        {
            self.backgroundImageView.hidden = YES;
            self.backgroundColor = [UIColor clearColor];
            
            self.titleLab.textColor = [UIColor whiteColor];
            self.colonLab.textColor = [UIColor whiteColor];
            self.contentLab.textColor = kALSHightBlueColor;
            
            self.detailLab1.textColor = [UIColor lightGrayColor];
            self.detailLab2.textColor = [UIColor lightGrayColor];
            self.separatorView.backgroundColor = [UIColor lightGrayColor];
        }
            break;
        case LGSketchCellFavoriteState:
        {
            if (self.content.door.favorite == 1) {
                self.backgroundImageView.hidden = NO;
            }else {
                self.backgroundImageView.hidden = YES;
            }

//            self.backgroundImageView.hidden = NO;
            self.backgroundColor = [UIColor clearColor];
            
            self.titleLab.textColor = [UIColor whiteColor];
            self.colonLab.textColor = [UIColor whiteColor];
            self.contentLab.textColor = kALSHightBlueColor;
            
            self.detailLab1.textColor = [UIColor lightGrayColor];
            self.detailLab2.textColor = [UIColor lightGrayColor];
            self.separatorView.backgroundColor = [UIColor lightGrayColor];
            
        }
        default:
            break;
    }
//    if (sketchCellState == LGSketchCellSearchState) {
//        
//        self.backgroundColor = [UIColor whiteColor];
//        
//        self.titleLab.textColor = [UIColor blackColor];
//        self.contentLab.textColor = [UIColor blackColor];
//        self.colonLab.textColor = [UIColor blackColor];
//        
//        self.detailLab1.textColor = kGrayColor(175);
//        self.detailLab2.textColor = kGrayColor(175);
//        self.separatorView.backgroundColor = kGrayColor(238);
//    }else {
//        self.backgroundColor = [UIColor clearColor];
//        
//        self.titleLab.textColor = [UIColor whiteColor];
//        self.colonLab.textColor = [UIColor whiteColor];
//        self.contentLab.textColor = kALSHightBlueColor;
//        
//        self.detailLab1.textColor = [UIColor lightGrayColor];
//        self.detailLab2.textColor = [UIColor lightGrayColor];
//        self.separatorView.backgroundColor = [UIColor lightGrayColor];
//    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
